import React,{Component} from 'react'
// import qs from 'querystring'

const data = [
  {id:'01',content:'欢迎光临'},
  {id:'02',content:'欢迎再来'},
  {id:'03',content:'别来了'},
]
export default class Detail extends Component{
  render(){

    //接收params参数
    const {id,title} = this.props.match.params

    // 接收 search 参数    parse方法：把k=v&k=v形式转为对象形式     slice():截取作用
    // const {search} = this.props.location
    // const {id,title} = qs.parse(search.slice(1))

    // 接收state参数
    // 这里的“ || {} ”是为了当history里面的state为空时，findResult不被视为报错
    // const {id,title} = this.props.location.state || {}

    const findResult = data.find((dataObj)=>{
      return dataObj.id === id
    }) || {}

    return (
      <ul>
        <li>ID:{id}</li>
        <li>TITLE:{title}</li>
        <li>CONTENT:{findResult.content}</li>
      </ul>
    )
  }
}